#include <cstdio>
#include <cassert>
#include <cstring>

char s[(int)1e5];

int main( int argc, char *argv[] )
{
  int T, x;
  assert(argc >= 2 && sscanf(argv[1], "%d", &T) == 1);
  T *= 60;
  while (gets(s))
  {
    char *t = strchr(s, '(');
    if (t && sscanf(t + 1, "%d", &x) == 1 && x > T)
      continue;
    puts(s);
  }
  return 0;
}
